package luanluan.utils.load 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	/**
	 * swf加载工具
	 * @author luanluan
	 */
	public class LSwfLoader implements ILoader 
	{
		//	*目标加载路径
		private var _url:String = "";
		
		//	*loader用来加载
		private var _loader:Loader;
		
		//	*加载完成的显示对象
		private var _view:DisplayObject;
		
		/**
		 * 加载swf
		 */
		public function LSwfLoader() 
		{
			_loader = new Loader();
		}
		
		/* INTERFACE luanluan.load.ILoader */
		
		public function start(url:String = ""):void 
		{
			_url = url;
			var urlReq:URLRequest = new URLRequest(_url);
			_loader.load(urlReq);
		}
		
		public function setProgress(func:Function):void 
		{
			_loader.addEventListener(ProgressEvent.PROGRESS , func);
		}
		
		public function setComplete(func:Function):void 
		{
			_loader.addEventListener(Event.COMPLETE , func);
		}
		
		public function setOpen(func:Function):void 
		{
			_loader.addEventListener(Event.OPEN , func);
		}
		
		public function setIOError(func:Function):void 
		{
			_loader.addEventListener(IOErrorEvent.IO_ERROR , func);
		}
		
		public function get url():String 
		{
			return _url;
		}
		
		public function get bytesLoaded():uint 
		{
			return _loader.contentLoaderInfo.bytesLoaded;
		}
		
		public function get bytesTotal():uint 
		{
			return _loader.contentLoaderInfo.bytesTotal;
		}
		
		public function get view():DisplayObject 
		{
			try
			{
				_view = (_loader.getChildAt(0) as DisplayObjectContainer).getChildAt(0);
			}
			catch (e:Error)
			{
				_view = null;
			}
			return _view;
		}
		
	}

}